package com.example.onlinefood.service;

import com.example.onlinefood.domain.User;
import com.example.onlinefood.mapper.UserMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
public class UserService {
    @Resource
    private UserMapper userMapper;

    public User getUserById(Integer id) {
        return userMapper.findById(id);
    }
    
    @Transactional
    public User updateUser(User user) {
        User existingUser = userMapper.findById(user.getId());
        if (existingUser == null) {
            return null;
        }
        
        // 更新用户信息
        userMapper.update(user);
        
        // 返回更新后的用户信息
        return userMapper.findById(user.getId());
    }
}